package jdk8demo.interfacefunction;

import java.util.Arrays;

public class MethodRefDemo {
	public static void main(String[] args) {
		int[] ints1 = new int[] { 1, 4, 3, 2, 5 };
		GetMax getMax = arrs -> {
			Arrays.sort(arrs);
			return arrs[arrs.length - 1];
		};

		GetMax getMax1 = MethodRef::getMax;// 静态方法引用
		MethodRef ref = new MethodRef();
		GetMax getMax2 = ref::getMax1;// 实例方法
		System.out.println(getMax.max(ints1));
		System.out.println(getMax1.max(ints1));
		System.out.println(getMax2.max(ints1));

		Str str = String::new;// 构造方法
		String s = str.str(new char[] { 'H', 'e', 'l', 'l', 'o' });
		System.out.println(s);
	}
}

class MethodRef {
	public static int getMax(int[] arrs) {
		Arrays.sort(arrs);
		return arrs[arrs.length - 1];
	}

	public int getMax1(int[] arrs) {
		Arrays.sort(arrs);
		return arrs[arrs.length - 1];
	}
}

interface GetMax {
	int max(int[] arrs);
}

interface Str {
	String str(char[] chars);
}